I noticed similar behaviour on iOS and worked around it using ProxyRepresentation, a bit like this:
struct DataShareItem: Transferable {
static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation {
try generateFile()
}
}
var data: Data
var filename: String
private func generateFile() throws → URL {
let tempFileURL = FileManager.default.temporaryDirectory
.appendingPathComponent(filename)
try data.write(to: tempFileURL)
return tempFileURL
}
}
I agree that it seems like the FileRepresentation approach should work though, so I think it's a framework bug.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: